<template>
  <slot v-if="hasPermission" />
</template>

<script setup>
import { computed } from 'vue'
import { useUserStore } from '@/store/user'

const props = defineProps({
  permission: [String, Array], // 支持字符串或数组
})
const userStore = useUserStore()

const hasPermission = computed(() => {
  if (!props.permission) return true
  const perms = Array.isArray(props.permission)
    ? props.permission
    : [props.permission]
  return perms.every((p) => userStore.userInfo?.permissions?.includes(p))
})
</script>
